// 引入数据库
const conn = require('../data');
const fs = require('fs');
// 初始化班级设置页面
module.exports.classInformation = (req, res) => {
    if(!req.session.login){
        res.redirect('/login');
        return;
      }
    conn.query('select * from class', (error, reslut) => {
        if (error) return console.log(error);
        res.render('classInformation', reslut[0]);
        // console.log(reslut[0])
    })
};
// 修改班级头像
module.exports.classUpload = (req, res) => {
    // console.log(req.file.buffer);
    fs.writeFile('./public/upload/' + req.file.originalname, req.file.buffer, (error, reslut) => {
        if (error) return console.log(error);
        res.json({
            pic: './upload/' + req.file.originalname
        });
    })
}
// 修改班级数据
module.exports.updateClass = (req, res) => {
    // console.log(req.body)
    let classArr = [req.body.pic, req.body.chinesename, req.body.englishname, req.body.label, req.body.id];
    // console.log(classArr)
    conn.query('update class set class_logo=?,class_chinesename=?,class_englishname=?,class_label=? where class_id=?', classArr, (error, reslut) => {
        if(error) return console.log(error);
        res.json({
            code:'100',
            message:'班级信息修改成功'
        })
    })
}